package cn.zhaozhiqi.autoconfiguration;

import cn.zhaozhiqi.properties.GeTuiProperties;
import cn.zhaozhiqi.template.GeTuiTemplate;
import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({GeTuiProperties.class})
public class GeTuiAutoConfiguration {

    @Bean
    public GeTuiTemplate geTuiTemplate(GeTuiProperties prop){
        // 设置httpClient最大连接数，当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
        System.setProperty("http.maxConnections", "200");
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        //填写应用配置
        apiConfiguration.setAppId(prop.getAppId());
        apiConfiguration.setAppKey(prop.getAppKey());//dw1WJMzqbV9j1VcCvuxoa2
        apiConfiguration.setMasterSecret(prop.getMasterSecret());
        // 接口调用前缀，请查看文档: 接口调用规范 -> 接口前缀
        apiConfiguration.setDomain(prop.getDomain());
        // 实例化ApiHelper对象，用于创建接口对象
        ApiHelper apiHelper = ApiHelper.build(apiConfiguration);

        return new GeTuiTemplate(apiHelper);
    }
}
